# 定义变量
BINARY_NAME=filescanner
GO=go
SRC_DIR=./src
BUILD_DIR=./bin

# 默认目标
.PHONY: all
all: clean build

# 清理
.PHONY: clean
clean:
	@echo "正在清理..."
	@rm -rf $(BUILD_DIR)
	@echo "清理完成"

# 构建
.PHONY: build
build:
	@echo "正在构建..."
	@mkdir -p $(BUILD_DIR)
	@cd $(SRC_DIR) && $(GO) build -o ../$(BUILD_DIR)/$(BINARY_NAME) .
	@echo "构建完成: $(BUILD_DIR)/$(BINARY_NAME)"

# 安装
.PHONY: install
install: build
	@echo "正在安装..."
	@cp $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin/
	@echo "安装完成: /usr/local/bin/$(BINARY_NAME)"

# 运行
.PHONY: run
run: build
	@echo "正在运行..."
	@$(BUILD_DIR)/$(BINARY_NAME)

# 测试
.PHONY: test
test:
	@echo "正在测试..."
	@cd $(SRC_DIR) && $(GO) test -v .
	@echo "测试完成"

# 帮助
.PHONY: help
help:
	@echo "可用命令:"
	@echo "  make all      - 清理并构建项目"
	@echo "  make clean    - 清理构建产物"
	@echo "  make build    - 构建项目"
	@echo "  make install  - 安装到系统"
	@echo "  make run      - 构建并运行项目"
	@echo "  make test     - 运行测试"
	@echo "  make help     - 显示帮助信息"
